package com.gztms.handler;

import com.gztms.utils.ResultUtil;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.LockedException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Zoey
 * @date 2023/4/18 22:24
 * @Description 登录失败处理类
 **/
@Component
public class UserLoginFailHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        if (e instanceof UsernameNotFoundException) {
            ResultUtil resultUtil = new ResultUtil(500,"用户名不存在");
        }
        if (e instanceof LockedException) {
            ResultUtil resultUtil = new ResultUtil(500,"用户名被禁用");
        }
        if (e instanceof BadCredentialsException) {
            ResultUtil resultUtil = new ResultUtil(500,"用户密码不正确");
        }

        ResultUtil resultUtil = new ResultUtil(500,"登陆失败");
    }
}
